<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/templates/template.xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:nu="http://nu.jcperera.homeip.net/facelets" xmlns:p="http://primefaces.org/ui">

	<ui:param name="title" value="NU Application Edit Web Info Site Page" />

	<f:metadata>
		<f:viewParam name="entityid" value="#{webInfoPatternBean.entityid}" />
		<f:viewParam name="entityid" value="#{webInfoValueBean.parentid}" />
	</f:metadata>

	<ui:define name="body">
		<p:outputPanel>
			<p:messages id="edit-messages" autoUpdate="true" closable="true" showDetail="true" redisplay="no"/>

			<p:panel id="parent-panel" header="Parent Web Info Site" style="margin-bottom:10px;">
				<h:panelGrid columns="2">
					<h:outputLabel for="parent-entityid" value="ID: " />
					<p:inputText id="parent-entityid" value="#{webInfoPatternBean.site.entityid}" required="false" label="ID" size="45"
						readonly="true" disabled="true" />

					<h:outputLabel for="parent-url" value="URL: *" />
					<p:inputText id="parent-url" value="#{webInfoPatternBean.site.url}" required="true" label="URL" size="150"
						readonly="true" disabled="true" />

					<h:outputLabel for="parent-parameters" value="Parameters: *" />
					<p:inputText id="parent-parameters" value="#{webInfoPatternBean.site.parameters}" required="true"
						label="Parameters" size="100" readonly="true" disabled="true" />
				</h:panelGrid>
			</p:panel>

			<p:panel id="edit-panel" header="Edit Web Info Pattern" style="margin-bottom:10px;">
				<h:panelGrid columns="3" style="margin-bottom:10px;">
					<h:outputLabel for="entityid" value="ID: " />
					<p:inputText id="entityid" value="#{webInfoPatternBean.entityid}" required="false" label="ID" size="45"
						readonly="true" disabled="true" />
					<p:message for="entityid" />

					<h:outputLabel for="xslPattern" value="XSL Pattern: *" />
					<p:inputText id="xslPattern" value="#{webInfoPatternBean.xslPattern}" required="true" label="XSL Pattern"
						size="150">
						<f:validateLength minimum="15" />
					</p:inputText>
					<p:message for="xslPattern" />

					<h:outputLabel for="format" value="Format: *" />
					<p:inputText id="format" value="#{webInfoPatternBean.format}" required="true" label="Format" size="100">
						<f:validateLength minimum="10" />
					</p:inputText>
					<p:message for="format" />

					<h:outputLabel for="fieldName" value="Field Name: *" />
					<p:inputText id="fieldName" value="#{webInfoPatternBean.fieldName}" required="true" label="Field Name" size="30">
						<f:validateLength minimum="2" />
					</p:inputText>
					<p:message for="fieldName" />

					<h:outputLabel for="isPrimary" value="Is Primary: *" />
					<p:selectBooleanButton id="isPrimary" value="#{webInfoPatternBean.isPrimary}" onLabel="Yes" offLabel="No"
						onIcon="ui-icon-check" offIcon="ui-icon-close" />
					<p:message for="isPrimary" />

				</h:panelGrid>

				<p:commandButton value="Save" actionListener="#{webInfoPatternBean.saveWebInfoPattern}" id="saveButton"
					icon="ui-icon-disk" update="edit-panel,edit-messages"></p:commandButton>

				<p:commandButton value="Delete" id="deleteButton" onclick="confirmation.show()" icon="ui-icon-trash" type="button">
				</p:commandButton>

				<p:button value="Go to parent" outcome="/pages/webinfosite/edit.xhtml?faces-redirect=true" process="@this">
					<f:param name="entityid" value="#{webInfoPatternBean.parentid}" />
				</p:button>

				<p:confirmDialog header="Confirmation"
					widgetVar="confirmation" severity="alert" closeOnEscape="true" appendToBody="true">
					<f:facet name="message">
						<h:outputText value="Are you sure you want to delete the entity?" />
						<br/>
						<h:outputText value="This will recursively delete ALL children entities" />
					</f:facet>
					<p:commandButton value="Yes" icon="ui-icon-check" action="#{webInfoPatternBean.deleteWebInfoPattern}" />
					<p:commandButton value="No" icon="ui-icon-close" onclick="confirmation.hide()" type="button" />
				</p:confirmDialog>
			</p:panel>

			<p:panel id="list-panel" header="List of Web Info Values for the Web Info Pattern" style="margin-bottom:10px;">
				<p:dataTable id="webInfoValueTable" var="webInfoValue" value="#{webInfoValueBean.webInfoValues}"
					widgetVar="webInfoValuesTable" emptyMessage="No Web Info Values found for the current Web Info Pattern"
					rowKey="#{webInfoValue.entityid}" paginator="true" rows="15" selection="#{webInfoValueBean.selectedWebInfoValue}"
					selectionMode="single">

					<p:ajax event="rowSelect" listener="#{webInfoValueBean.onRowSelect}" />

					<p:column id="idColumn" headerText="Id" width="5%">
						<h:outputText value="#{webInfoValue.entityid}" />
					</p:column>

					<p:column id="followUpEnabledColumn" headerText="Follow up enabled?" width="5%">
						<h:outputText value="#{webInfoValue.followUpEnabled}" />
					</p:column>

					<p:column id="matchingRegexColumn" headerText="Matching Regex" width="25%">
						<h:outputText value="#{webInfoValue.matchingRegex}" />
					</p:column>

					<p:column id="pendingCheckColumn" headerText="Pending check?" width="5%">
						<h:outputText value="#{webInfoValue.pendingCheck}" />
					</p:column>

					<p:column id="createdByColumn" headerText="Created By" width="10%">
						<h:outputText value="#{webInfoValue.createdBy}" />
					</p:column>

					<p:column id="createdWhenColumn" headerText="Created When" width="10%">
						<h:outputText value="#{webInfoValue.createdWhenAsDate}">
							<f:convertDateTime dateStyle="short" timeZone="EST" type="both" />
						</h:outputText>
					</p:column>

					<p:column id="modifiedByColumn" headerText="Modified By" width="10%">
						<h:outputText value="#{webInfoValue.modifiedBy}" />
					</p:column>

					<p:column id="modifiedWhenColumn" headerText="Modified When" width="10%">
						<h:outputText value="#{webInfoValue.modifiedWhenAsDate}">
							<f:convertDateTime dateStyle="short" timeZone="EST" type="both" />
						</h:outputText>
					</p:column>

					<p:column id="localVersionColumn" headerText="Local" width="5%">
						<h:outputText value="#{webInfoValue.localVersion}" />
					</p:column>

					<p:column id="globalVersionColumn" headerText="Global" width="5%">
						<h:outputText value="#{webInfoValue.globalVersion}" />
					</p:column>
				</p:dataTable>

				<br style="font-size: 8px;" />

				<p:button value="Create New" outcome="/pages/webinfovalue/edit.xhtml?faces-redirect=true" process="@this">
					<f:param name="parentid" value="#{webInfoValueBean.parentid}" />
				</p:button>
			</p:panel>
		</p:outputPanel>
	</ui:define>
</ui:composition>